package com.example.demo.dao;

import com.example.demo.bean.Order;
import com.example.demo.bean.SeckillOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

//操作订单数据库
@Mapper
public interface OrderDao {

    @Select("select * from sk_order_info where user_id=#{userId} and goods_id=#{goodsId}")
    public Order findOrder(Order order);

    /**
     * 通过@SelectKey使insert成功后返回主键id，也就是订单id
     * @param orderInfo
     * @return
     */
    @Insert("insert into sk_order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date) values("
            + " #{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "select last_insert_id()")
    public long insert(Order orderInfo);


    @Insert("insert into sk_order (user_id, order_id,goods_id) values(#{userId},#{orderId}, #{goodsId}")
    public int insertSeckillOrder(SeckillOrder order);


    @Select("select * from sk_order_info where id=#{id}")
    public Order findOrderById(Long orderId);
}

